package com.example.superssssss.messagesender;

import android.Manifest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends BaseActivity {

    private EditText thephoneNumber = null;
    private EditText text = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        thephoneNumber = (EditText) findViewById(R.id.editText);
        text = (EditText) findViewById(R.id.editText2);
        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new MySendMessageListener());
        /**
         * 获取短信管理器
         */
    }

    private class MySendMessageListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            final String phoneNumber = thephoneNumber.getText().toString().trim();
            final String message = text.getText().toString().trim();

            if ("".equals(phoneNumber) || "".equals(message)) {
                Toast.makeText(MainActivity.this, "null", Toast.LENGTH_SHORT).show();
                return;
            }

            Log.i("Supersssssss", "onClick: " + message);

            performCodeWithPermission("发送短信权限", new PermissionCallback() {
                @Override
                public void hasPermission() {
                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage(phoneNumber, null, message, null, null);
                }

                @Override
                public void noPermission() {

                }
            }, Manifest.permission.SEND_SMS);


        }
    }
}
